﻿using System;

namespace JetBlack.TopicBus.ExcelAddin
{
    internal class ClientKey : IEquatable<ClientKey>
    {
        public readonly string Host;
        public readonly int Port;

        public ClientKey(string host, int port)
        {
            Host = host;
            Port = port;
        }

        public override bool Equals(object obj)
        {
            return Equals(obj as ClientKey);
        }

        public bool Equals(ClientKey other)
        {
            return
                other != null
                && String.Equals(Host, other.Host, StringComparison.InvariantCultureIgnoreCase)
                && Port == other.Port;
        }

        public override int GetHashCode()
        {
            return (Host == null ? 0 : Host.GetHashCode()) ^ Port.GetHashCode();
        }

        public override string ToString()
        {
            return String.Format("{0}:{1}", Host, Port);
        }
    }
}
